gdkevents: Don't ignore modifiers that are not currently active
authorSimon McVittie <smcv@debian.org>
Sat, 17 Sep 2022 17:53:00 +0000 (18:53 +0100)
committerSimon McVittie <smcv@debian.org>
Sat, 17 Sep 2022 21:23:08 +0000 (22:23 +0100)
commit0b7f513848f0ed8319a67279153fb736fb568c18
treee03904c3432961b07f463a89d1217a6dd09d5ce3
parentbcbc09f759d3925dc43b522783757346f3eea151
gdkevents: Don't ignore modifiers that are not currently active

The X11 backend can mark modifiers like Shift as consumed even if they
aren't actually active, which seems to be something to do with making
shortcuts like `<Control><Shift>plus` and `<Control>plus` work as
intended regardless of whether the plus symbol is obtained by pressing
Shift and a key (like `+/=` on American, British or French keyboards)
or not (like `*/+` on German keyboards).

However, this can go badly wrong when the modifier is *not* pressed.
For example, terminals normally have separate bindings for `<Control>c`
(send SIGINT) and `<Control><Shift>c` (copy). If we disregard the
consumed modifiers completely, when the X11 backend marks Shift as
consumed, pressing Ctrl+c would send SIGINT *and* copy to the clipboard,
which is not what was intended.

By masking out the members of `consumed` that are not in `state`, we
get the same interpretation for X11 and Wayland, and ensure that
keyboard shortcuts that explicitly mention Shift can only be triggered
while holding Shift. It continues to be possible to trigger keyboard
shortcuts that do not explicitly mention Shift (such as `<Control>plus`)
while holding Shift, if the backend reports Shift as having been
consumed in order to generate the plus keysym.

Bug: https://gitlab.gnome.org/GNOME/gtk/-/issues/5095
Bug-Debian: https://bugs.debian.org/1016927
Signed-off-by: Simon McVittie <smcv@debian.org>
Forwarded: https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/5037

Gbp-Pq: Name gdkevents-Don-t-ignore-modifiers-that-are-not-currently-a.patch
gdk/gdkevents.c